package com.web.exiaodao.business.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.web.exiaodao.business.entity.MakeMoneyTable;

/**
 * 赚钱记录
 */
public interface MakeMoneyTableRepository extends
		PagingAndSortingRepository<MakeMoneyTable, Long>,
		JpaSpecificationExecutor<MakeMoneyTable> {

	public MakeMoneyTable findByIdAndStatusNot(Long id, Integer status);
	
	public List<MakeMoneyTable> findByUserIdAndStatusNot(Long userId, Integer status);

    /**
     * 计算userId用户账户所有的亲币
     * @param userId
     * @return
     */
    @Query(value = "SELECT sum(make_money_cost * consume_or_make_money) FROM tb_xa_makemoneytable WHERE user_id = ?1  AND status <> 3 ", nativeQuery = true)
    public Long calculate(long userId);
}
